package com.qf.im.controller;


import com.qf.im.base.BaseController;
import com.qf.im.base.R;
import com.qf.im.entity.User;
import com.qf.im.entity.vo.FriendVo;
import com.qf.im.service.FriendshipService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 好友关系表(Friendship)表控制层
 *
 * @author makejava
 * @since 2023-10-31 10:26:05
 */
@RestController
@RequestMapping("/friendship")
public class FriendshipController extends BaseController<FriendshipService> {


    /**
     * 查询我的所有好友
     * @return
     */
    @RequestMapping("/myFriends")
    public R queryMyFriends(){
        List<User> users = getBaseService().queryMyFriends();

        //将好友的用户信息 转换成VO对象
        List<FriendVo> friendsList = users.stream().map(user -> new FriendVo()
                        .setId(user.getId()).setName(user.getNickname()).setPhone(user.getUsername()).setImg(user.getHeader()))
                .collect(Collectors.toList());


        return R.succ(friendsList);
    }
}

